<template>
  <div class="parent">
    <div class="child">
      <el-form :model="form" label-width="auto" style="max-width: 600px">
        <el-form-item label="用户名">
          <el-input v-model="form.UserName" />
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.Password" show-password />
        </el-form-item>
        <el-form-item label="验证码">
          <div id="app">
            <h1>滑动验证码示例</h1>
            <Captcha />
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">登录</el-button>
          <el-button type="primary" @click="onSubmits">测试登录</el-button>
          <!-- <el-button>Cancel</el-button> -->
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import axios from 'axios';
import { useRouter } from 'vue-router';
import { useCounterStore } from '@/stores/counter';
import Captcha from './module components/Captcha.vue';

const store = useCounterStore();
const router = useRouter();

//#region 滑动验证码



//#endregion


//#region  登录
const form = reactive({
  UserName: '',
  Password: '',
})

const onSubmit = () => {
  axios.get("https://localhost:7174/api/Message/Login", {
    params: {
      UserName: form.UserName,
      Password: form.Password
    }
  }).then(res => {
    if (res.data.code == 202) {
      ElMessage.success(res.data.msg)
      store.ccstore.nickName = res.data.data.nickName
      store.ccstore.userId = res.data.data.userId
      store.ccstore.userName = res.data.data.userName
      store.ccstore.depId = res.data.data.depId
      store.ccstore.levelRoleId = res.data.data.levelRoleId
      router.push("/UserList")
      console.log(res.data.data.nickName)
    } else {
      ElMessage.error(res.data.msg)
    }
  })
}

const onSubmits = () => {
  router.push("/MianView")
}

//#endregion

</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>